package com.haixiaoke.saas.enterprise.house.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HouseOperatingRecord;
import com.haixiaoke.saas.house.service.IHouseOperatingRecordService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋操作记录Controller
 *
 * @author panda
 * @date 2023-10-26
 */
@RestController
@RequestMapping("/enterprise/house/operatingRecord")
public class EnterpriseHouseOperatingRecordController extends BaseController {
    @Autowired
    private IHouseOperatingRecordService houseOperatingRecordService;

    /**
     * 查询房屋操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseOperatingRecord houseOperatingRecord) {
        startPage();
        List<HouseOperatingRecord> list = houseOperatingRecordService.selectHouseOperatingRecordList(houseOperatingRecord);
        return getDataTable(list);
    }

    /**
     * 导出房屋操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseOperatingRecord houseOperatingRecord) {
        List<HouseOperatingRecord> list = houseOperatingRecordService.selectHouseOperatingRecordList(houseOperatingRecord);
        ExcelUtil<HouseOperatingRecord> util = new ExcelUtil<HouseOperatingRecord>(HouseOperatingRecord.class);
        util.exportExcel(response, list, "房屋操作记录数据");
    }

    /**
     * 获取房屋操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:query')")
    @GetMapping(value = "/{houseOperatingRecordId}")
    public AjaxResult getInfo(@PathVariable("houseOperatingRecordId") String houseOperatingRecordId) {
        return success(houseOperatingRecordService.selectHouseOperatingRecordByHouseOperatingRecordId(houseOperatingRecordId));
    }

    /**
     * 新增房屋操作记录
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:add')")
    @PostMapping
    public AjaxResult add(@RequestBody HouseOperatingRecord houseOperatingRecord) {
        return toAjax(houseOperatingRecordService.insertHouseOperatingRecord(houseOperatingRecord));
    }

    /**
     * 修改房屋操作记录
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody HouseOperatingRecord houseOperatingRecord) {
        return toAjax(houseOperatingRecordService.updateHouseOperatingRecord(houseOperatingRecord));
    }

    /**
     * 删除房屋操作记录
     */
    @PreAuthorize("@ss.hasPermi('saas-business:HouseOperatingRecord:remove')")
    @DeleteMapping("/{houseOperatingRecordIds}")
    public AjaxResult remove(@PathVariable String[] houseOperatingRecordIds) {
        return toAjax(houseOperatingRecordService.deleteHouseOperatingRecordByHouseOperatingRecordIds(houseOperatingRecordIds));
    }
}
